package com.max.eshop.services;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.max.eshop.storage.Storage;

public class BookService {
	Storage s;

	public BookService(Storage storage) {
		this.s = storage;
	}

	public void show() {
		s.showBooks();
	}

	public void add(String name, String dateOfPublication, String description,
		 Integer count, Integer price) {
		Date dateOfPub = null;
	
		try {
			dateOfPub = new SimpleDateFormat("dd.MM.yyyy")
					.parse(dateOfPublication);
			
		} catch (ParseException e) {
			e.printStackTrace();
		}
		s.addBook(name, dateOfPub, description, count, price);
	}
	 public Integer count(){
		 return s.countBooks();
	 }

	public void delete(int i) {
		s.deleteBook(i - 1);
	}

	public void showStale() {
		s.showStaleBooks();
	}

	public void sortedByCount() {
		s.sortedBooksByCount();
	}

	public void sortedByPrice() {
		s.sortedBooksByPrice();
	}

	public void sortedByDateOfPublication() {
		s.sortedBooksByDateOfPublication();
	}

	public void sortedByAlphabet() {
		s.sortedBooksByAlphabet();
	}

	public void sortedStaleBooksByPrice() {
		s.sortedStaleBooksByPrice();
	}

	public void sortedStaleBooksByDateOfReceipt() {
		s.sortedStaleBooksByDateOfReceipt();
	}
}
